package net.sky.oaxz.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import net.sky.oaxz.bean.XzGrade;
import net.sky.oaxz.bean.XzSubject;

/**
 * 操作学科
 * @author Jason
 *
 */
@SuppressWarnings("unused")
public class XzSubjectDao extends BaseDao{
	private Connection conn = null;
	private PreparedStatement pstmt = null;
	private ResultSet rs = null;
	
	/**
	 * 添加学科
	 * @param 
	 * @return
	 */
	public int addSub(XzSubject xs){
		StringBuffer sql=new StringBuffer("insert into xz_subject values (SQ_XZSUBJECT_ID.nextval,?,?,?)");
		String [] params=new String[] {xs.getSubName(),xs.getSubDesc(),xs.getSubStatus()+""};
		return this.executeSQL(sql.toString(), params);
	}
	/**
	 * 显示所有学科
	 * @param schId
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List searchSub(){
		List list =new ArrayList();
		StringBuffer sql=new StringBuffer("select * from xz_subject order by sub_id");
		try{
			conn=this.getConn();
			pstmt=conn.prepareStatement(sql.toString());
			rs=pstmt.executeQuery();
			while(rs.next()){
				XzSubject xzs=new XzSubject();
				xzs.setSubId(rs.getInt("sub_id"));
				xzs.setSubName(rs.getString("sub_name"));
				xzs.setSubDesc(rs.getString("sub_desc"));
				xzs.setSubStatus(rs.getInt("sub_status"));
				list.add(xzs);
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			this.closeAll(conn, pstmt, rs);
		}
		return list;
	}
}
